/**
 * 
 */
package com.newworld.dmsapp2.fragment.adapter;

/**
 * @author zuo
 *
 */
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.newworld.dmsapp2.R;
import com.newworld.dmsapp2.fragment.bean.History;

/**
 * @author zuo 历史查询列表界面的adapter
 * 
 */
public class HistorySearchAdapter extends BaseAdapter {

	private List<History> historyList;
	private LayoutInflater inflater;
	Context context;

	public HistorySearchAdapter(Context context, List<History> historyList) {
		inflater = LayoutInflater.from(context);
		this.historyList = historyList;
		this.context = context;
	}

	@Override
	public int getCount() {
		return historyList.size();
	}

	@Override
	public Object getItem(int position) {
		return historyList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(
					R.layout.activity_history_search_list_item, parent, false);
			holder = new ViewHolder();
			holder.locationTv = (TextView) convertView
					.findViewById(R.id.tv_history_item_location);
			holder.repairPeopleTv = (TextView) convertView
					.findViewById(R.id.tv_history_item_people_repair);
			holder.statusTv = (TextView) convertView
					.findViewById(R.id.tv_history_item_status);
			holder.timeTv = (TextView) convertView
					.findViewById(R.id.tv_history_item_time);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		History item = historyList.get(position);
		holder.locationTv.setText(item.getLocation());
		holder.repairPeopleTv.setText(item.getRepairPeople());
		holder.statusTv.setText(item.getStatus().subSequence(0, 1));
		holder.timeTv.setText(item.getTime());
		return convertView;
	}

	private class ViewHolder {

		TextView locationTv;
		TextView repairPeopleTv;
		TextView statusTv;
		TextView timeTv;
	}
}